<template>
	<view class="template-build tn-safe-area-inset-bottom">
    
    <view class="tn-safe-area-inset-bottom" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
      
	  <view class="justify-content-item tn-margin tn-text-bold tn-text-xl">委托公司</view>
      <view class="tn-margin tn-bg-gray--light" style="border-radius: 10rpx;padding: 20rpx 30rpx;color:#AAAAAA;">
      	<input placeholder="" name="input" :value="formData.businessName" disabled></input>
      </view>
	  
	  <view class="justify-content-item tn-margin tn-text-bold tn-text-xl">任务类型</view>
	  <view class="tn-margin tn-bg-gray--light" style="border-radius: 10rpx;padding: 20rpx 30rpx;color:#AAAAAA;">
	  	<input placeholder="" name="input" :value="formData.signingService" disabled></input>
	  </view>
	  
	  <view class="justify-content-item tn-margin tn-text-bold tn-text-xl">发布时间</view>
	  <view class="tn-margin tn-bg-gray--light" style="border-radius: 10rpx;padding: 20rpx 30rpx;color:#AAAAAA;">
	  	<input placeholder="" name="input" :value="formData.releaseDate" disabled></input>
	  </view>
	  
	  <view class="justify-content-item tn-margin tn-text-bold tn-text-xl">任务说明</view>
      <view class="tn-margin tn-bg-gray--light tn-padding" style="border-radius: 10rpx;color:#AAAAAA;">
        <textarea style="height: 120px;" maxlength="300" placeholder="" :value="'　　因委托方业务发展，现需要若干有相关服务经验或能力的自由职业者提供'+ formData.signingService +'，具体要求和费用由委托方公布。'" disabled></textarea>
      </view>
      
    </view>
    
    <!-- 悬浮按钮-->
    <view class="tn-flex tn-footerfixed">
      <view class="tn-flex-1 justify-content-item tn-margin-sm tn-text-center">
        <tn-button v-if="formData.signingStatus==='0'" shape="round" backgroundColor="#ff3d57" padding="40rpx 0" width="70%" shadow fontBold @click="receiveTask()">
		  <text class="tn-color-white" style="font-size: 16px;">领取任务</text>
        </tn-button>
		<tn-button v-if="formData.signingStatus==='1'" shape="round" disabled="true" backgroundColor="#b8b7b8" padding="40rpx 0" width="70%" shadow fontBold>
		  <text class="tn-color-white" style="font-size: 16px;">已签约</text>
		</tn-button>
      </view>
    </view>
	  
	</view>
</template>

<script>
  import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
import api, { queryServiceTaskById } from '../store/api';
	export default {
    name: 'TemplateBuild',
    mixins: [template_page_mixin],
		data() {
			return {
				formData: {
					id: '',
					phone: '',
					signingStatus: '0',//签约状态：0-未签约，1-已签约
					companyId: '',
					companyName: '',
					companyCode: '',
					businessId: '',
					businessName: '',
					tenantId: '',
					signingService: '',
					signingServiceId: '',
					releaseDate: '',
					signContent: '',
				},
				wxCode: '',
				userInfo:{
					avatarUrl: '',
					nickName: '',
					phone: ''
				},
			}
		},
		onLoad(e) {
			console.log("==e===：",e);
			// scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
			const scene = decodeURIComponent(e.scene)
			// const scene = ''
			// 获取本地存储的用户信息
			let userInfo = uni.getStorageSync('ys_user_info');
			if(userInfo){
				this.userInfo = JSON.parse(userInfo);
				this.formData.phone = this.userInfo.phone;
				this.formData.id = scene;
			}else{//重新授权
				let params = '/signingPages/taskdetails?scene=' + e.scene;
				uni.reLaunch({
					url: '/signingPages/authorization?pages=' + encodeURIComponent(JSON.stringify(params))
				});
			}
			console.log("本地存储的用户信息：",this.userInfo);
			if(!e.memberInfo){
				//获取数据
				this.queryServiceTask(this.formData.id,this.formData.phone);
			}else{
				this.formData = JSON.parse(decodeURIComponent(e.memberInfo));
			}
			// console.log("==1=formData===：",JSON.stringify(this.formData));
		},
		methods: {
			//查询签约任务信息
			queryServiceTask(id,phone){
				if(!id || !phone){
					uni.showToast({title: "参数错误",icon: "none",mask: true,});
					return;
				}
				uni.showLoading({
					title: '请稍后...',
					mask: true,
				})
				this.$requestApi.queryServiceTaskById({id: id, phone: phone}).then(res => {
					uni.hideLoading();
					if(res.success){
						this.formData = res.result;
					}else{
						uni.showToast({title: res.message,icon: "none",mask: true,});
						return;
					}
				});
			},
			receiveTask(){
				if(this.formData.signingStatus==='0'){
					if(!this.formData.companyId || !this.formData.businessId || !this.formData.tenantId){
						uni.showToast({title: "参数错误！",icon: "none",mask: true,});
						return;
					}
					uni.reLaunch({
						url: '/signingPages/confirmAgreement?memberInfo=' + encodeURIComponent(JSON.stringify(this.formData))
					});
				}else{
					uni.showToast({title: "已签约",icon: "none",mask: true,});
					return;
				}
		
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.template-edit{
	}
  
  /* 底部悬浮按钮 start*/
  .tn-tabbar-height {
  	min-height: 100rpx;
  	height: calc(120rpx + env(safe-area-inset-bottom) / 2);
  }
  .tn-footerfixed {
    position: fixed;
    width: 100%;
    bottom: calc(30rpx + env(safe-area-inset-bottom));
    z-index: 1024;
    box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0);
    
  }
  /* 底部悬浮按钮 end*/
  
  /* 标签内容 start*/
  .tn-tag-content {
    &__item {
      display: inline-block;
      line-height: 45rpx;
      padding: 10rpx 30rpx;
      margin: 20rpx 20rpx 5rpx 0rpx;
      
      &--prefix {
        padding-right: 10rpx;
      }  
    }
  }
  /* 标签内容 end*/
</style>